package axis

import (
	

	
	
)

// PlacementMode represents the axis display placement mode.
type PlacementMode string

const (
	Hidden PlacementMode = "hidden"
	Auto   PlacementMode = "auto"
	Left   PlacementMode = "left"
	Right  PlacementMode = "right"
)

// ScaleMode represents the axis scale distribution.
type ScaleMode uint8

const (
	Linear ScaleMode = iota
	Log2
	Log10
)

// Option represents an option that can be used to configure an axis.
type Option func(axis *Axis) error

// Axis represents a visualization axis.
type Axis struct {
	fieldConfig *sdk.FieldConfig
}

// New creates a new Axis configuration.
func ( *sdk.FieldConfig,  ...Option) (*Axis, error) {
	 := &Axis{fieldConfig: }

	for ,  := range  {
		if  := ();  != nil {
			return nil, 
		}
	}

	return , nil
}

// Placement defines how the axis should be placed in the panel.
func ( PlacementMode) Option {
	return func( *Axis) error {
		.fieldConfig.Defaults.Custom.AxisPlacement = string()

		return nil
	}
}

// SoftMin defines a soft minimum value for the axis.
func ( int) Option {
	return func( *Axis) error {
		.fieldConfig.Defaults.Custom.AxisSoftMin = &

		return nil
	}
}

// SoftMax defines a soft maximum value for the axis.
func ( int) Option {
	return func( *Axis) error {
		.fieldConfig.Defaults.Custom.AxisSoftMax = &

		return nil
	}
}

// Min defines a hard minimum value for the axis.
func ( float64) Option {
	return func( *Axis) error {
		.fieldConfig.Defaults.Min = &

		return nil
	}
}

// Max defines a hard maximum value for the axis.
func ( float64) Option {
	return func( *Axis) error {
		.fieldConfig.Defaults.Max = &

		return nil
	}
}

// Unit sets the unit of the data displayed in this series.
func ( string) Option {
	return func( *Axis) error {
		.fieldConfig.Defaults.Unit = 

		return nil
	}
}

// Scale sets the scale to use for the Y-axis values..
func ( ScaleMode) Option {
	return func( *Axis) error {
		 := struct {
			 string `json:"type"`
			  int    `json:"log,omitempty"`
		}{
			: "linear",
		}

		switch  {
		case Linear:
			. = "linear"
		case Log2:
			. = "log"
			. = 2
		case Log10:
			. = "log"
			. = 10
		}

		.fieldConfig.Defaults.Custom.ScaleDistribution = 

		return nil
	}
}

// Label sets a Y-axis text label.
func ( string) Option {
	return func( *Axis) error {
		.fieldConfig.Defaults.Custom.AxisLabel = 

		return nil
	}
}

// Decimals sets how many decimal points should be displayed.
func ( int) Option {
	return func( *Axis) error {
		if  < 0 {
			return fmt.Errorf("decimals must be greater than 0: %w", errors.ErrInvalidArgument)
		}

		.fieldConfig.Defaults.Decimals = &

		return nil
	}
}